package offer.algorithm;

/**
 * Description：
 * Author: zhangc
 * Date：2017/7/18 21:04
 */
public class Fibonacci9 {

    public static  int getNum(int index){
        if(index < 0)
            return 0;
        if(index ==0 || index==1)
            return index;
        else
            return getNum(index - 2) + getNum(index - 1);
    }

    public static int getFibonacciNum(int index){
        if(index < 0)
            return 0;
        if(index ==0 || index==1)
            return index;

        int n1 = 0,n2 = 1;
        int temp;
        for (int i = 1; i < index; i++) {
            temp = n2;
            n2 = n1 + n2;
            n1 = temp;
        }
        return n2;

    }

}
